﻿using B.S.Procurement.Domain;
using B.S.Procurement.Error;
using B.S.Procurement.Read.Api.Application.Command.ProcurementCommand;
using B.S.Procurement.Read.Api.Application.Command.PurchaseDetailsCommand;
using B.S.Procurement.Read.Api.DTO;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Procurement.Read.Api.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ProcurementController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ProcurementController> logger;

        public ProcurementController(IMediator mediator, ILogger<ProcurementController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 显示查询采购信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<List<ProcurementDto>>> QueryProcurement([FromQuery] QueryProcurementCommand request)
        {
            logger.LogInformation("查询采购信息成功");
            return mediator.Send(request);
        }

        /// <summary>
        /// 反填采购信息表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ProcurementModel>>> ShowProcurement([FromQuery] ShowProcurementCommand request)
        {
            logger.LogInformation("反填采购信息成功");
            return await mediator.Send(request);
        }

        /// <summary>
        /// 显示查询采购明细
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<List<PurchaseDto>>> QueryPurchaseDetails([FromQuery] QueryPurchaseDetailsCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 反填采购信息明细
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<PurchaseDetails>>> ShowPurchaseDetails([FromQuery] ShowPurchaseDetailsCommand request)
        {
            return await mediator.Send(request);
        }


    }
}
